package com.gzc.just.play.last.war.centralserver.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import jakarta.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;

@Component("central-centralServerConfig")
@Configuration
public class CentralServerConfig {
    private static final Logger logger = LoggerFactory.getLogger(CentralServerConfig.class);
    
    @Value("${central.server.id:1}")
    private int centralServerId;
    
    @Value("${central.server.name:CentralServer}")
    private String centralServerName;
    
    @Value("${central.server.listen.ip:0.0.0.0}")
    private String centralServerListenIp;
    
    @Value("${central.server.listen.port:30003}")
    private int centralServerListenPort;
    
    @Value("${central.server.max.msg.size:1024000}")
    private int centralServerMaxMsgSize;
    
    @Value("${db.host:localhost}")
    private String dbHost;
    
    @Value("${db.port:3306}")
    private int dbPort;
    
    @Value("${db.name:lastwar}")
    private String dbName;
    
    @Value("${redis.host:localhost}")
    private String redisHost;
    
    @Value("${redis.port:6379}")
    private int redisPort;
    
    @Value("${match.queue.timeout:30000}")
    private long matchQueueTimeout;
    
    @Value("${match.team.min.size:1}")
    private int matchTeamMinSize;
    
    @Value("${match.team.max.size:5}")
    private int matchTeamMaxSize;
    
    @Value("${match.max.teams.per.game:2}")
    private int matchMaxTeamsPerGame;
    
    @Value("${battle.max.duration:3600000}")
    private long battleMaxDuration;
    
    @Value("${battle.min.players:2}")
    private int battleMinPlayers;
    
    @Value("${battle.max.players:10}")
    private int battleMaxPlayers;
    
    @Value("${battle.room.ttl:600000}")
    private long battleRoomTTL;
    
    @Value("${guild.max.members:100}")
    private int guildMaxMembers;
    
    @Value("${guild.level.max:10}")
    private int guildLevelMax;
    
    @Value("${quest.max.active:5}")
    private int questMaxActive;
    
    @Value("${quest.expire.time:86400000}")
    private long questExpireTime;
    
    @Value("${ranking.update.interval:60000}")
    private long rankingUpdateInterval;
    
    @Value("${ranking.cache.size:1000}")
    private int rankingCacheSize;
    
    @Value("${log.server.ip:127.0.0.1}")
    private String logServerIp;
    
    @Value("${log.server.port:50001}")
    private int logServerPort;
    
    @PostConstruct
    public void init() {
        logger.info("CentralServerConfig initialized:");
        logger.info("- CentralServer ID: {}, Name: {}", centralServerId, centralServerName);
        logger.info("- Listen on: {}:{}", centralServerListenIp, centralServerListenPort);
        logger.info("- Database: {}:{}/{}", dbHost, dbPort, dbName);
        logger.info("- Redis: {}:{}", redisHost, redisPort);
        logger.info("- Match Config: Team Size {}-{}, Timeout: {}ms", 
                   matchTeamMinSize, matchTeamMaxSize, matchQueueTimeout);
        logger.info("- Battle Config: Players {}-{}, Max Duration: {}ms, Room TTL: {}ms",
                   battleMinPlayers, battleMaxPlayers, battleMaxDuration, battleRoomTTL);
        logger.info("- Guild Config: Max Members: {}, Max Level: {}", 
                   guildMaxMembers, guildLevelMax);
        logger.info("- Quest Config: Max Active: {}, Expire Time: {}ms",
                   questMaxActive, questExpireTime);
        logger.info("- Ranking Config: Update Interval: {}ms, Cache Size: {}",
                   rankingUpdateInterval, rankingCacheSize);
        logger.info("- Log Server: {}:{}", logServerIp, logServerPort);
    }
    
    // Getter methods
    public int getCentralServerId() {
        return centralServerId;
    }
    
    public String getCentralServerName() {
        return centralServerName;
    }
    
    public String getCentralServerListenIp() {
        return centralServerListenIp;
    }
    
    public int getCentralServerListenPort() {
        return centralServerListenPort;
    }
    
    public int getCentralServerMaxMsgSize() {
        return centralServerMaxMsgSize;
    }
    
    public String getDbHost() {
        return dbHost;
    }
    
    public int getDbPort() {
        return dbPort;
    }
    
    public String getDbName() {
        return dbName;
    }
    
    public String getRedisHost() {
        return redisHost;
    }
    
    public int getRedisPort() {
        return redisPort;
    }
    
    public long getMatchQueueTimeout() {
        return matchQueueTimeout;
    }
    
    public int getMatchTeamMinSize() {
        return matchTeamMinSize;
    }
    
    public int getMatchTeamMaxSize() {
        return matchTeamMaxSize;
    }
    
    public int getMatchMaxTeamsPerGame() {
        return matchMaxTeamsPerGame;
    }
    
    public long getBattleMaxDuration() {
        return battleMaxDuration;
    }
    
    public int getBattleMinPlayers() {
        return battleMinPlayers;
    }
    
    public int getBattleMaxPlayers() {
        return battleMaxPlayers;
    }
    
    public long getBattleRoomTTL() {
        return battleRoomTTL;
    }
    
    public int getGuildMaxMembers() {
        return guildMaxMembers;
    }
    
    public int getGuildLevelMax() {
        return guildLevelMax;
    }
    
    public int getQuestMaxActive() {
        return questMaxActive;
    }
    
    public long getQuestExpireTime() {
        return questExpireTime;
    }
    
    public long getRankingUpdateInterval() {
        return rankingUpdateInterval;
    }
    
    public int getRankingCacheSize() {
        return rankingCacheSize;
    }
    
    public String getLogServerIp() {
        return logServerIp;
    }
    
    public int getLogServerPort() {
        return logServerPort;
    }
    
    public List<Integer> getAvailableMaps() {
        List<Integer> maps = new ArrayList<>();
        maps.add(1);
        maps.add(2);
        maps.add(3);
        maps.add(4);
        maps.add(5);
        return maps;
    }
}
